home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_01
/
1001046a
< prev
next >
Wrap
Text File
|
1991-10-04
|
1KB
|
64 lines
/*
* Listing 2: main() routine and test code for get_str().
* Includes the OS-dependent routines sys_getchar()
* and sys_putchar().
*/
#include <stdio.h>
#include <stdlib.h>
#include <bios.h>
#include <string.h>
#define INBUFSIZ 70
char inbuf[INBUFSIZ + 1];
void get_str( char *str, int len );
void main( void )
{
while (1)
{
printf("\ntype 'quit' to quit.\nprompt> ");
get_str(inbuf, INBUFSIZ);
if (stricmp(inbuf, "quit") == 0)
break;
printf(" Got: \"%s\"\n", inbuf);
}
}
/*********************************************************
* The following two routines will need to be changed,
* in order to use get_str() in a different environment.
*********************************************************/
/*
* Put a character to the output device.
* Expand \n to \r\n.
*/
void sys_putchar( char ch )
{
putchar(ch);
if (ch == '\n')
putchar('\r');
}
/*
* Get a character from the input device.
* Use the BIOS call so we can detect arrow keys.
*/
int sys_getchar( void )
{
int ch;
ch = bioskey(0); /* wait and get a key */
if ((ch & 0xff) != 0) /* if not an extended key, */
ch &= 0xff; /* use only the ASCII part */
return (ch);
}